<?php
$id				= gpc_getIntPost("id",$id);
$oldUrl 		= gpc_getStringPost("oldUrl");
$name	        = gpc_getStringPost("Name");
$urlstring		= gpc_getStringPost("URL",$name);
$title			= gpc_getStringPost("Title",$name);
$type 			= $module;
$parentId       = gpc_getIntPost("ParentId");
$TopBottomOrder	= gpc_getIntPost("TopBottomOrder",-1);
$order 			= gpc_getIntPost("Order",-1);
$Status 		= gpc_getIntPost("Status");
$HasHighLine	= gpc_getBoolPost("HasHighLine",0);
$sologan 		= gpc_getStringPost("Sologan");
$description 	= gpc_getStringPost("Description");
$Intro			= gpc_getStringPost("Intro");
$Tag 			= gpc_getStringPost("Tag");

$metatitle 		= gpc_getStringPost("MetaTitle",$name);
$metakeywords 	= gpc_getStringPost("MetaKeywords");
$metadescription= gpc_getStringPost("MetaDescription",strip_tags($description));

$ImgIntro 		= gpc_getStringPost('ImgIntro');
$ImgBanner 		= gpc_getStringPost('ImgBanner');
$ImgBackground	= gpc_getStringPost('ImgBackground');
//------==============-------------------
$urlstring      = Trim_Url($urlstring);
$description    = replace_pathlocal($description);
$Intro		    = replace_pathlocal($Intro);
$metadescription=strip_tags($metadescription);

if(empty($name))
{
	error_transfer("Name is empty!");
}
//check url:
CheckUrlString($urlstring,"tblcategory",$parentId);

$order=GetOrderForInsert($TopBottomOrder,$order,$parentId,"tblcategory");

if($act=="insert" || $id==0)
{
    $HasHighLine	= intval($HasHighLine);
    $postdate   = date("Y-m-d");
    $poster     = getUserNamePost();
	//get order category same parent;

	$sql_insert = "INSERT INTO tblproduct_category
				(iParentId,cUrlString , cName,iOrder, cDescription,cIntro,cType,
				cMetaTitle, cMetaDescription, cMetaKeywords ,cImage, cBanner,cBackground,
				iStatus,iHasHighLine,dPostDate,cPoster,cLanguage)
			VALUE
				('$parentId','$urlstring','$name','$order','$description','$Intro','$type',
				'$metatitle','$metadescription','$metakeywords','$ImgIntro','$ImgBanner','$ImgBackground',
				'$Status','$HasHighLine','$postdate','$poster','$language')";

	$dbsql->query($sql_insert);


    Insert_Tracking("Add Category : $name ");
    page_transfer("Add Category Success !",getUrlBack());
}
elseif($id>0)
{
    if(intval($id)==0)return false;
    $order      = intval($order);
	$sql_update = "UPDATE  tblproduct_category SET
				iParentId	 	= $parentId,
				cUrlString 		= '$urlstring',
				cName		 	= '$name',
				cDescription 	= '$description',
				cIntro			='$Intro',
				".(!empty($type)? "cType	= '$type',": '')."
				iStatus			= '$Status',
				cMetaTitle 		= '$metatitle',
				cMetaDescription= '$metadescription',
				cMetaKeywords 	= '$metakeywords',
				cImage 			= '$ImgIntro',
				cBanner 		= '$ImgBanner',
                cBackground     = '$ImgBackground',
                ".(($order>0)? 'iOrder='.$order.',' : '')."
				iHasHighLine	= '$HasHighLine'

		WHERE  iId 	= $id";

	$dbsql->query($sql_update);

    Insert_Tracking( " Edit Categories : $name ");

    $pagetr     = getUrlBack();
    page_transfer("Update Category Success",$pagetr);
}
exit();
?>